﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Rapid
{
    class Comment
    {
        static RapidDataDataContext db = new RapidDataDataContext();

        //public static IEnumerable<string> GetComments()
        //{
        //    return db.Observations.Where(ob => ob.TypeDrug != 2).Select(ob => ob.Comments);
        //}
        //public static string GetComments(bool isMonitoring)

        public static string GetComment(EObservation observation, ETest testType)
        {
            try
            {
                var strComment = db.Observations.Single(ob => ob.TypeDrug == 1 && ob.Flag == (byte)1 && ob.ObservationType == observation.ToString()).Comments;
                if (!string.IsNullOrEmpty(strComment))
                    return strComment + "(" + testType + ")" + Environment.NewLine;
                return string.Empty;
            }
            catch
            {
                return string.Empty;
            }
        }

        public static string GetMonitoringComment(EObservation observation, ETest testType)
        {
            try
            {
                var strComment = db.Observations.Single(ob => ob.TypeDrug == 2 && ob.Flag == (byte)1 && ob.ObservationType == observation.ToString()).Comments;
                if (!string.IsNullOrEmpty(strComment))
                    return strComment + "(" + testType + ")" + Environment.NewLine;
                return string.Empty;
            }
            catch
            {
                return string.Empty;
            }
        }

        public static string GetCommonComment(EObservationCommon observation, ETestCommon testType)
        {
            try
            {
                var strComment = db.Observations.Single(ob => ob.TypeDrug == 3 && ob.Flag == (byte)1 && ob.ObservationType == observation.ToString()).Comments;
                if (!string.IsNullOrEmpty(strComment))
                    return strComment + "(" + testType + ")" + Environment.NewLine;
                return string.Empty;
            }
            catch
            {
                return string.Empty;
            }
        }

        public static string GetFlagComments()
        {
            string comments = string.Empty;
            foreach (var ele in TestResults.DicResultsShort())
            {
                if (ele.Value.testType == ETest.MTD && TestResults.isMonitoring)
                    comments += Comment.GetMonitoringComment(ele.Value.observation, ele.Key);
                else
                    comments += Comment.GetComment(ele.Value.observation, ele.Key);
            }

            foreach (var ele in TestResults.DicCommonResults)
            {
                comments += Comment.GetCommonComment(ele.Value.observation, ele.Key);
            }
            return comments;
        }
    }
}
